<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    var x={1:2,3:4};
    var y = clone(x);

    /**
     * 复制对象的函数方法
     * @param obj
     * @returns {*}
     */
    function clone(obj)
    {
        var o,i,j,k;
        if(typeof(obj)!="object" || obj===null)return obj;
        if(obj instanceof(Array))
        {
            o=[];
            i=0;j=obj.length;
            for(;i<j;i++)
            {
                if(typeof(obj[i])=="object" && obj[i]!=null)
                {
                    o[i]=arguments.callee(obj[i]);
                }
                else
                {
                    o[i]=obj[i];
                }
            }
        }
        else
        {
            o={};
            for(i in obj)
            {
                if(typeof(obj[i])=="object" && obj[i]!=null)
                {
                    o[i]=arguments.callee(obj[i]);
                }
                else
                {
                    o[i]=obj[i];
                }
            }
        }

        return o;
    }
</script>
</body>
</html>